package com.gitee.wsl.ext.array

import com.gitee.wsl.ext.bitcode.umod
import com.gitee.wsl.lang.arraylist.DoubleArrayList
import com.gitee.wsl.lang.arraylist.FloatArrayList
import com.gitee.wsl.lang.arraylist.IntArrayList

fun <T> List<T>.getCyclic(index: Int): T = this[index umod this.size]
fun <T> List<T>.getCyclicOrNull(index: Int): T? = if (this.isEmpty()) null else this.getOrNull(index umod this.size)

fun <T> Array<T>.getCyclic(index: Int) = this[index umod this.size]
fun IntArray.getCyclic(index: Int) = this[index umod this.size]
fun FloatArray.getCyclic(index: Int) = this[index umod this.size]
fun DoubleArray.getCyclic(index: Int) = this[index umod this.size]
fun IntArrayList.getCyclic(index: Int) = this.getAt(index umod this.size)
fun FloatArrayList.getCyclic(index: Int) = this.getAt(index umod this.size)
fun DoubleArrayList.getCyclic(index: Int) = this.getAt(index umod this.size)

//fun <T> Array2<T>.getCyclic(x: Int, y: Int) = this[x umod this.width, y umod this.height]
//fun IntArray2.getCyclic(x: Int, y: Int) = this[x umod this.width, y umod this.height]
//fun FloatArray2.getCyclic(x: Int, y: Int) = this[x umod this.width, y umod this.height]
//fun DoubleArray2.getCyclic(x: Int, y: Int) = this[x umod this.width, y umod this.height]
